/*
 * SpaceBattleInterface.cpp
 *
 *  Created on: Oct 23, 2011
 *      Author: gonzalo
 */

#include "SpaceBattleInterface.h"
#include "../persistencia/Persistor.h"
#include "../common/Translator/Translator.h"
#include "../common/Constantes.h"

SpaceBattleInterface::SpaceBattleInterface(std::string scenarioName,bool) {
	this->scenarioName =scenarioName;
	esServer =true;
	shipStatusXML = NULL;
	readXML();
}

SpaceBattleInterface::SpaceBattleInterface(std::string owner){
	this->owner = owner;
	esServer = false;
	readXML();
}
SpaceBattleInterface::~SpaceBattleInterface() {
	if (shipStatusXML != NULL)
		delete shipStatusXML;

	while (!asteroidesXML.empty()) {
		delete asteroidesXML.back();
		asteroidesXML.pop_back();
	}
}

ShipStatus* SpaceBattleInterface::getShip(){
	return shipStatusXML;
}

void SpaceBattleInterface::readXML(){
	int error = Persistor::getElements(this->asteroidesXML, &(this->shipStatusXML));

	if(error != PERSISTER_SUCCESS){
		Logger::log("SpaceBattleInterface","readXML","Error en la lectura del XML");
	}
}

std::list<Asteroide*> SpaceBattleInterface::getAsteroides(){
	if (esServer) {
		return asteroidesXML;
	}

	return Translator::translateAsteroideDTO(asteroides);
}

std::string SpaceBattleInterface::getOwner(){
	return this->owner;
}

void SpaceBattleInterface::setScenearioElements(std::list<DTOAsteroide*> listElements){
	this->asteroides = listElements;
}

